﻿Public Class ClsDSaModSolutionFile
    Inherits ClsFile
    'represents aMod Solution file

#Region "Attributes"
#Region "Private attributes"
    Private MoDSaModSolution As DsAmodSolution = Nothing 'aMod Solution DS
    Private MbFileWasModified As Boolean = True 'indicates if file was modified since last save    
#End Region
#End Region
#Region "Constructors"
    Sub New()
        MyBase.New()
    End Sub

    Sub New(ByVal IsPath As String)
        MyBase.New(IsPath)
    End Sub
#End Region
#Region "Properties"
#Region "Public attributes"
    Public Property FileWasModified() As Boolean
        Get
            Return MbFileWasModified
        End Get
        Set(ByVal IbValue As Boolean)
            If MbFileWasModified <> IbValue Then
                MbFileWasModified = IbValue

                'raise event
                RaiseEvent MMFileWasChanged()
            End If
        End Set
    End Property
    Public ReadOnly Property DSaModSolution() As DsAmodSolution
        Get
            Return MoDSaModSolution
        End Get
    End Property
    'directory with solution file - LEVEL #1
    Public ReadOnly Property SolutionDirectory() As String
        Get
            Return IO.Path.GetDirectoryName(MsPath)
        End Get
    End Property
    'directory with project files - directory on the same level as aMod Solution file - LEVEL #2
    Public ReadOnly Property ProjectsDirectory() As String
        Get
            Return IO.Path.Combine(SolutionDirectory, GetSolutionName())
        End Get
    End Property
    'directory with aMod directories - LEVEL #3
    Public ReadOnly Property aModDirectoriesDirectory() As String
        Get
            Return IO.Path.Combine(ProjectsDirectory, GetModulesDirectoryName)
        End Get
    End Property
    'directory with aMod file - LEVEL #4
    Public ReadOnly Property aModFileDirectory(ByVal IsaModName As String) As String
        Get
            Return IO.Path.Combine(aModDirectoriesDirectory, ISaModName)
        End Get
    End Property
    'path to aMod file - LEVEL #4
    Public ReadOnly Property aModFilePath(ByVal IsaModName As String) As String
        Get
            Return IO.Path.Combine(aModFileDirectory(IsaModName), (IsaModName & ".aMod"))
        End Get
    End Property
#End Region
#End Region
#Region "Events"
    Public Event MMFileWasChanged() 'event is raised after value MbFileWasChanged was changed
#End Region
#Region "Functions"
#Region "Open file&DS, Save file&DS, Close file&DS"
    'sets new file mode
    Public Function CreateNewFile(ByVal IsSolutionName As String, ByVal IsModulesDirectoryName As String) As GeActionResult
        Try
            If MeStateOfFile = GeFileState.kkNotInit Then
                MeStateOfFile = GeFileState.kkNewFile
                MoDSaModSolution = New DsAmodSolution

                InsertaModSolutionInfo(IsSolutionName, IsModulesDirectoryName)
                FileWasModified = True

                Return GeActionResult.kkOk
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'inits after new file
    Public Function InitAfterNewFile(ByVal IsPath As String) As GeActionResult
        Try
            If MeStateOfFile = GeFileState.kkNewFile Then
                MeStateOfFile = GeFileState.kkOpened
                MsPath = IsPath

                Return GeActionResult.kkOk
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'new physical aMod Solution file with empty DS
    Public Function CreateVirginFile(ByVal IsSolutionName As String, ByVal IsSolutionPath As String, ByVal IsModulesDirectoryName As String)
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk

            LeResult = CreateNewFile(IsSolutionName, IsModulesDirectoryName)
            If LeResult = GeActionResult.kkOk Then InitAfterNewFile(IsSolutionPath)
            If LeResult = GeActionResult.kkOk Then SaveFile(True)

            Return LeResult
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'open file
    Public Overrides Function OpenFile() As GeActionResult
        Try
            If MyBase.OpenFile = GeActionResult.kkOk Then
                MoDSaModSolution = New DsAmodSolution
                If MoDSaModSolution.ReadXml(MsPath, XmlReadMode.IgnoreSchema) Then
                    MeStateOfFile = GeFileState.kkOpened
                    FileWasModified = False

                    Return GeActionResult.kkOk
                Else
                    Throw New Exception
                End If
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'saves aMod Solution file and creates directory for aMod files - depends on parameter
    Public Function SaveFile(ByVal IbCreateDirectory As Boolean) As GeActionResult
        Try
            If MeStateOfFile = GeFileState.kkOpened Then
                MoDSaModSolution.WriteXml(MsPath, XmlWriteMode.WriteSchema)
                FileWasModified = False

                'creating project directory (for later vbproj file) and  directory for modules
                If IbCreateDirectory Then
                    TryToCreateFolder(aModDirectoriesDirectory, True)
                End If
                Return GeActionResult.kkOk
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'closes file
    Public Overrides Function CloseFile() As GeActionResult
        Try
            If MyBase.CloseFile = GeActionResult.kkOk Then
                MeStateOfFile = GeFileState.kkNotInit
                MsPath = ""
                FileWasModified = True
                Return GeActionResult.kkOk
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#Region "Manipulating with DS"
#Region "INSERT"
    'insert info about aMod solution
    Private Function InsertaModSolutionInfo(ByVal IsSolutionName As String, ByVal IsModulesDirectoryName As String)
        Try
            Dim LoRow As DataRow
            LoRow = MoDSaModSolution.SolutionInfoTable.NewRow()

            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.SolutionName) = IsSolutionName
            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.Created) = GetTodaysDateTimeString()
            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.LastUpdate) = GetTodaysDateTimeString()
            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.RTFdescription) = GsStringNullValue
            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.FlowChartData) = GsStringNullValue
            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.ModulesDirectoryName) = IsModulesDirectoryName

            MoDSaModSolution.SolutionInfoTable.Rows.Add(LoRow)

            FileWasModified = True
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'inserts new module to DS
    Public Function InsertNewModule(ByVal IsModuleName As String, ByVal IsHumanModuleName As String) As GeActionResult
        'check for duplicity of ModuleName was already permormed (during creating aMod file) so I dont need to test duplicity again here
        Try
            Dim LoRow As DataRow

            LoRow = MoDSaModSolution.ModulesTable.NewRow()
            LoRow(DSaModSolution.ModulesSysnames.Columns.ModuleName) = IsModuleName
            LoRow(DSaModSolution.ModulesSysnames.Columns.HumanModuleName) = IsHumanModuleName
            LoRow(DSaModSolution.ModulesSysnames.Columns.Created) = GetTodaysDateTimeString()
            LoRow(DSaModSolution.ModulesSysnames.Columns.LastUpdate) = GetTodaysDateTimeString()
            LoRow(DSaModSolution.ModulesSysnames.Columns.RTFdescription) = GsStringNullValue
            LoRow(DSaModSolution.ModulesSysnames.Columns.RelativePath) = GetSolutionName() & "\Modules\" & IsModuleName & "\" & IsModuleName & ".aMod" ''DOCASNE - urobit funkciu

            MoDSaModSolution.ModulesTable.Rows.Add(LoRow)

            FileWasModified = True
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#Region "SELECT"
    'gets a row from Modules table by ModuleName
    Public Function GetModulesRowByModuleName(ByVal IsModuleName As String, Optional ByVal IbSilentMode As Boolean = False) As DataRow
        Try
            Dim LoRows As DataRow()
            LoRows = MoDSaModSolution.ModulesTable.Select(String.Format("{0}='{1}'", DSaModSolution.ModulesSysnames.Columns.ModuleName, IsModuleName))

            If LoRows.Length = 1 Then
                Return LoRows(0)
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            If Not IbSilentMode Then LogEventFromException(ex, , )
            Return Nothing
        End Try
    End Function
    'gets a row from Modules table by HumanModuleName
    Private Function GetModulesRowByHumanModuleName(ByVal IsHumanModuleName As String, Optional ByVal IbSilentMode As Boolean = False) As DataRow
        Try
            Dim LoRows As DataRow()
            LoRows = MoDSaModSolution.ModulesTable.Select(String.Format("{0}='{1}'", DSaModSolution.ModulesSysnames.Columns.HumanModuleName, IsHumanModuleName))

            If LoRows.Length = 1 Then
                Return LoRows(0)
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            If Not IbSilentMode Then LogEventFromException(ex, , )
            Return Nothing
        End Try
    End Function
    'gets ModulesDirectoryName
    Public Function GetModulesDirectoryName() As String
        Try
            Dim LoRow As DataRow
            LoRow = GetSolutionInfoRow()

            Return LoRow(DSaModSolution.SolutionInfoSysnames.Columns.ModulesDirectoryName)

        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'gets a aMod solution's name
    Public Function GetSolutionName() As String
        Try
            Dim LoRow As DataRow
            LoRow = GetSolutionInfoRow()

            Dim LsSolutionName As String = ""
            LsSolutionName = LoRow(DSaModSolution.SolutionInfoSysnames.Columns.SolutionName)
            If LsSolutionName <> "" Then
                Return LsSolutionName
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'gets relative path of aMod file
    Public Function GetRelativePathOfaModFile(ByVal IsModuleName As String) As String
        Try
            Dim LoRow As DataRow = GetModulesRowByModuleName(IsModuleName)

            If LoRow IsNot Nothing Then
                Return LoRow(DSaModSolution.ModulesSysnames.Columns.RelativePath)
            Else
                Throw New Exception
            End If

        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    ' '' ''gets absolute path of aMod file
    '' ''Public Function GetAbsolutePathOfaModFile(ByVal IsModuleName As String) As String
    '' ''    Try
    '' ''        Dim LsRelativePath As String = GetRelativePathOfaModFile(IsModuleName)
    '' ''        Dim LsAbsolutePath As String = IO.Path.Combine(SolutionDirectory, LsRelativePath)

    '' ''        Return LsAbsolutePath
    '' ''    Catch ex As Exception
    '' ''        LogEventFromException(ex, , , )
    '' ''        Return ""
    '' ''    End Try
    '' ''End Function
    'gets RTF description of module
    Public Function GetRTFdescriptionOfModule(ByVal IsModuleName As String) As String
        Try
            Dim LoRow As DataRow
            LoRow = GetModulesRowByModuleName(IsModuleName)

            Return LoRow(DSaModSolution.ModulesSysnames.Columns.RTFdescription)
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'gets RTF description of solution
    Public Function GetRTFdescriptionOfSolution() As String
        Try
            Dim LoRow As DataRow
            LoRow = GetSolutionInfoRow()

            Return LoRow(DSaModSolution.SolutionInfoSysnames.Columns.RTFdescription)
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'gets class diagram data
    Public Function GetClassDiagramData() As String
        Try
            Dim LoRow As DataRow
            LoRow = GetSolutionInfoRow()

            Return LoRow(DSaModSolution.SolutionInfoSysnames.Columns.FlowChartData)
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'gets row from SolutionInfo table
    Public Function GetSolutionInfoRow() As DataRow
        Try
            Dim LoRows As DataRow()
            LoRows = DSaModSolution.SolutionInfo.Select
            If LoRows IsNot Nothing AndAlso LoRows.Length = 1 Then
                Return LoRows(0)
            Else
                Throw New Exception
            End If
        Catch ex As Exception
            LogEventFromException(ex, , )
            Return Nothing
        End Try
    End Function
#End Region
#Region "UPDATE"
    'update diagram of modules
    Public Function UpdateDiagramData(ByVal IsDiagramData As String) As GeActionResult
        Try
            Dim LoRows As DataRow()
            LoRows = MoDSaModSolution.SolutionInfoTable.Select()

            If LoRows.Length = 1 Then
                LoRows(0)(DSaModSolution.SolutionInfoSysnames.Columns.FlowChartData) = IsDiagramData
            Else
                Throw New Exception
            End If

            FileWasModified = True
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'update RTF description of module
    Public Function UpdateRTFdescriptionOfModule(ByVal IsModuleName As String, ByVal IsRTFtext As String) As GeActionResult
        Try
            Dim LoRow As DataRow
            LoRow = GetModulesRowByModuleName(IsModuleName)

            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.RTFdescription) = IsRTFtext

            FileWasModified = True
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'update RTF description of solution
    Public Function UpdateRTFdescriptionOfSolution(ByVal IsRTFtext As String) As GeActionResult
        Try
            Dim LoRow As DataRow
            LoRow = GetSolutionInfoRow()

            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.RTFdescription) = IsRTFtext

            FileWasModified = True
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'update module name
    Public Function UpdateModuleName(ByVal IsOldModuleName As String, ByVal IsNewModuleName As String) As GeActionResult
        Try
            If GetModulesRowByModuleName(IsNewModuleName, True) Is Nothing Then
                'if module with new name doesnt exist
                Dim LoRow As DataRow = GetModulesRowByModuleName(IsOldModuleName)
                LoRow(DSaModSolution.ModulesSysnames.Columns.ModuleName) = IsNewModuleName
                Return GeActionResult.kkOk
            Else
                'theres another module with new name
                Return GeActionResult.kkCancel
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'update human module name
    Public Function UpdateHumanModuleName(ByVal IsOldHumanModuleName As String, ByVal IsNewHumanModuleName As String) As GeActionResult
        Try
            Select Case MessageBox.Show("Premenovanim modulu zmenite nazov aMod suboru a adresara, v ktorom sa nachadza. Ak ste uz generovali Visual Studio projekt alebo jeho sucasti, bude potrebne tieto vygenerovat opat, aby sa obnovili referencie vo Visual Studio projekte. " & vbNewLine & vbNewLine & "Ste si isti, ze chcete modul premenovat?", "Premenovanie modulu", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
                Case DialogResult.No
                    Return GeActionResult.kkCancel
                Case DialogResult.Yes
                    If GetModulesRowByHumanModuleName(IsNewHumanModuleName, True) Is Nothing Then
                        'if module with new human name doesnt exist
                        Dim LoRow As DataRow = GetModulesRowByHumanModuleName(IsOldHumanModuleName)
                        Dim LsOldFolderPath As String = ""
                        Dim LsNewFolderPath As String = ""
                        Dim LsOldFilePath As String = ""
                        Dim LsNewFilePath As String = ""

                        'try to create file and folder paths
                        Try
                            'assigning values
                            LsOldFolderPath = aModFileDirectory(IsOldHumanModuleName)
                            LsNewFolderPath = aModFileDirectory(IsNewHumanModuleName)
                            LsOldFilePath = IO.Path.Combine(LsNewFolderPath, IsOldHumanModuleName & ".aMod") 'file will have old name but in new folder
                            LsNewFilePath = aModFilePath(IsNewHumanModuleName)

                            'checking some special stuff :-) - length of path, file name and invalid chars
                            If IsValidFileName(IsNewHumanModuleName) = GeActionResult.kkOk AndAlso IsValidFolderPath(LsOldFolderPath) = GeActionResult.kkOk AndAlso IsValidFolderPath(LsNewFolderPath) = GeActionResult.kkOk AndAlso IsValidFolderPath(LsOldFilePath) = GeActionResult.kkOk AndAlso IsValidFolderPath(LsNewFilePath) = GeActionResult.kkOk Then
                            Else
                                Throw New Exception
                            End If

                        Catch ex As Exception
                            LogEventFromException(ex, , , False)
                            MessageBox.Show("Novy nazov modulu obsahuje zakazane znaky, ktore sa nemozu vyskytovat v ceste k suboru/adresaru alebo je tato cesta prilis dlha. Prosim zmente nazov modulu.", "Neprijatelny nazov modulu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                            Return GeActionResult.kkError
                        End Try

                        'everything with paths is ok
                        If TryToRenameFolder(LsOldFolderPath, LsNewFolderPath) = GeActionResult.kkOk Then
                            If TryToRenameFile(LsOldFilePath, LsNewFilePath) = GeActionResult.kkOk Then
                                LoRow(DSaModSolution.ModulesSysnames.Columns.HumanModuleName) = IsNewHumanModuleName
                                'also saving of aMod solution file coz HumanModuleName was changed in aMod solution file DS and not in DsAModOneVersion DS, so theres no "diskette icon" evidence of this change                      
                                SaveFile(False)
                                Return GeActionResult.kkOk
                            Else
                                'folder was renamed and file wasnt renamed --> try to rename folder back to original name
                                TryToRenameFolder(LsNewFolderPath, LsOldFolderPath)
                                Return GeActionResult.kkError
                            End If
                        Else
                            'folder wasnt renamed
                            Return GeActionResult.kkError
                        End If
                    Else
                        'theres another module with new human name
                        Return GeActionResult.kkSpecial
                    End If
            End Select
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'update solution name
    Public Function UpdateSolutionName(ByVal IsNewSolutionName As String) As GeActionResult
        Try
            Select Case MessageBox.Show("Premenovanim projektu zmenite nazov hlavneho projektoveho suboru a nazov adresara s ostatnymi projektovymi subormi. Ak ste uz generovali Visual Studio projekt alebo jeho sucasti, bude potrebne tieto vygenerovat opat, aby sa obnovili referencie vo Visual Studio projekte. " & vbNewLine & vbNewLine & "Ste si isti, ze chcete projekt premenovat?", "Premenovanie projektu", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
                Case DialogResult.No
                    Return GeActionResult.kkCancel
                Case DialogResult.Yes
                    Dim LoRow As DataRow = GetSolutionInfoRow()
                    Dim LsOldFolderPath As String = ""
                    Dim LsNewFolderPath As String = ""
                    Dim LsOldFilePath As String = ""
                    Dim LsNewFilePath As String = ""

                    'try to create file and folder paths
                    Try
                        'assigning values
                        LsOldFolderPath = ProjectsDirectory
                        LsNewFolderPath = IO.Path.Combine(IO.Path.GetDirectoryName(ProjectsDirectory), IsNewSolutionName)
                        LsOldFilePath = Path
                        LsNewFilePath = IO.Path.Combine(IO.Path.GetDirectoryName(LsOldFilePath), IsNewSolutionName & ".aModProj")

                        'checking some special stuff :-) - length of path, file name and invalid chars
                        If IsValidFileName(IsNewSolutionName) = GeActionResult.kkOk AndAlso IsValidFolderPath(LsOldFolderPath) = GeActionResult.kkOk AndAlso IsValidFolderPath(LsNewFolderPath) = GeActionResult.kkOk AndAlso IsValidFolderPath(LsOldFilePath) = GeActionResult.kkOk AndAlso IsValidFolderPath(LsNewFilePath) = GeActionResult.kkOk Then
                        Else
                            Throw New Exception
                        End If

                    Catch ex As Exception
                        LogEventFromException(ex, , , False)
                        MessageBox.Show("Novy nazov projektu obsahuje zakazane znaky, ktore sa nemozu vyskytovat v ceste k suboru/adresaru alebo je tato cesta prilis dlha. Prosim zmente nazov projektu.", "Neprijatelny nazov projektu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                        Return GeActionResult.kkError
                    End Try

                    'everything with paths is ok
                    If TryToRenameFolder(LsOldFolderPath, LsNewFolderPath) = GeActionResult.kkOk Then
                        If TryToRenameFile(LsOldFilePath, LsNewFilePath) = GeActionResult.kkOk Then
                            LoRow(DSaModSolution.SolutionInfoSysnames.Columns.SolutionName) = IsNewSolutionName
                            SetNewFilePath(LsNewFilePath)
                            'also saving of aMod file coz VersionModuleName was changed in aMod file DS and not in DsAModOneVersion DS, so theres no "diskette icon" evidence of this change                      
                            SaveFile(False)
                            Return GeActionResult.kkOk
                        Else
                            'folder was renamed and file wasnt renamed --> try to rename folder back to original name
                            TryToRenameFolder(LsNewFolderPath, LsOldFolderPath)
                            Return GeActionResult.kkError
                        End If
                    Else
                        'folder wasnt renamed
                        Return GeActionResult.kkError
                    End If
            End Select
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#End Region
#Region "Support functions"
    'makes next unique ModuleName in mask "BaseNameIndex" - BaseName=string, Index=number
    Public Function MakeNextUniqueModuleName(ByVal IsOriginalModuleName As String) As String
        Try
            Dim LiIndex As Integer = 1
            Dim LsNewModuleName As String = ""


            If GetModulesRowByModuleName(IsOriginalModuleName, True) Is Nothing Then
                Return IsOriginalModuleName
            Else
                '50x checking for unique AppTableName
                For LiI As Integer = 1 To 50
                    LsNewModuleName = IsOriginalModuleName & LiIndex.ToString
                    If GetModulesRowByModuleName(LsNewModuleName, True) Is Nothing Then Return LsNewModuleName
                    LiIndex += 1
                Next
            End If

            'after unsuccessful attempts return original name
            Return IsOriginalModuleName
        Catch ex As Exception
            LogEventFromException(ex, , , )
            'on error return original name
            Return IsOriginalModuleName
        End Try
    End Function
    'makes next unique HumanModuleName in mask "BaseNameIndex" - BaseName=string, Index=number
    Public Function MakeNextUniqueHumanModuleName(ByVal IsOriginalHumanModuleName As String) As String
        Try
            Dim LiIndex As Integer = 1
            Dim LsNewHumanModuleName As String = ""


            If GetModulesRowByHumanModuleName(IsOriginalHumanModuleName, True) Is Nothing Then
                Return IsOriginalHumanModuleName
            Else
                '50x checking for unique AppTableName
                For LiI As Integer = 1 To 50
                    LsNewHumanModuleName = IsOriginalHumanModuleName & LiIndex.ToString
                    If GetModulesRowByHumanModuleName(LsNewHumanModuleName, True) Is Nothing Then Return LsNewHumanModuleName
                    LiIndex += 1
                Next
            End If

            'after unsuccessful attempts return original name
            Return IsOriginalHumanModuleName
        Catch ex As Exception
            LogEventFromException(ex, , , )
            'on error return original name
            Return IsOriginalHumanModuleName
        End Try
    End Function
    'makes absolute path for new module
    'Private Function MakeAbsolutePathForNewModule(ByVal IsModuleName As String)
    '    Return "\" & IsModuleName & ".amod"
    'End Function
    'gets moduls names wirt path for generating
    Public Function GetModulesForGenerating() As Dictionary(Of String, String)
        Try
            Dim LoModulesDict As Dictionary(Of String, String) = New Dictionary(Of String, String) 'dictionary with module name and path to its aMod file
            Dim LsModuleName As String 'module name
            For Each LoModuleDataRow As DataRow In MoDSaModSolution.ModulesTable.Rows
                LsModuleName = LoModuleDataRow(DSaModSolution.ModulesSysnames.Columns.ModuleName)
                LoModulesDict.Add(LsModuleName, aModFilePath(LsModuleName)) ''DOCASNE - pouzit RelativePath z aModu
            Next

            Return LoModulesDict
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
#End Region

#End Region

End Class